home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 11066 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.3 KB

  1. Path: newshost.cyberramp.net!news
  2. From: sinan@cyberramp.net (John Noland)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: problem w/ realloc
  5. Date: 21 Mar 1996 20:20:18 GMT
  6. Organization: Prose Software
  7. Distribution: usa
  8. Message-ID: <4isdm2$a44@newshost.cyberramp.net>
  9. References: <4iqef0$dqq@montana.avicom.net>
  10. NNTP-Posting-Host: ramp1-21.cyberramp.net
  11. X-Newsreader: WinVN 0.99.5
  12.  
  13. In article <4iqef0$dqq@montana.avicom.net>, zoot@montana.avicom.net says...
  14. >
  15. >I've been porting a piece of code from AIX 3.2.5 to linux 1.2.8
  16. >(gcc 2.7.0) recently, and finaly chased down the last :-) bug.  The code 
  17. >assumes that if you have a memory block, and you realloc it smaller, it 
  18. >doesn't move the block of memory, it just makes the "usable size" of it 
  19. >smaller. (in fact, my textbook ("advanced programming in the unix 
  20. >environment" stevens) supports this usage) unfortunately, xxgdb has 
  21. >revealed that the realloc is moving my pointer!  am I mistaken about the 
  22. >standards, or is this a special case I'm not aware of?
  23. >any help appreciated-
  24.  
  25. It is not a special case. realloc() adjusts the size of the allocated block
  26. to the size you pass, copying the contents to a new location if necessary.
  27. Therefore, because the new block can be in a new memory location, the pointer
  28. returned by realloc() is *NOT* guaranteed to be the pointer passed into it.
  29.  
  30. -John
  31.  
  32.